﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using PlayingCardLib;

namespace DealCards
{
    public partial class Form1 : Form
    {
        private Deck deck;
        private List<Image> faces = new List<Image>();
        private Image back;
        private PlayingCard card;
        public Form1()
        {
            InitializeComponent();
            
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // deck = new Deck();
            deck = new Deck(CardRank.Ace, CardRank.King, CardRank.Queen, CardRank.Jack);
            // Assign images for cards
            for (int i = 0; i <= 51; i++)
            {
                faces.Add(cardImages.Images[i]);
            }
            back = cardImages.Images[56];
            deck.AssignImages(faces, back);

            ResetDeck();
        }

        // Reset the Deck
        // It does not work, as the deck is empty!
        private void ResetDeck()
        {
            deck.Shuffle();

            // Set Picture Boxes
            PictureBoxDeck.Image = back;
            PictureBoxCard.Image = null;
        }

        // Get the top card when click the deck.
        private void PictureBoxDeck_Click(object sender, EventArgs e)
        {
            if (!deck.IsEmpty())
            {
                card = deck.DealTopCard();
                PictureBoxCard.Image = card.FrontImage;
                textCardName.Text = card.ToString();
            }
            else
            {
                PictureBoxDeck.Image = null;
            }
            
        }

        // Reset Button
        private void btnReset_Click(object sender, EventArgs e)
        {
            ResetDeck();
        }
    }
}
